#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<vector>
#include<string>

using namespace std;

vector<int> findAnagrams(string s, string p) {
    vector<int> ret;
    ret.resize(s.size());
    int sLen = s.size();
    int pLen = p.size();
    if (sLen < pLen)
    {
        return ret;
    }

    vector<int> sCount(26, 0);
    vector<int> pCount(26, 0);
    for (int i = 0; i < pLen; i++)
    {
        sCount[p[i] - 'a']++;
        pCount[p[i] - 'a']++;
    }

    int index = 0;
    if (sCount == pCount)
    {
        ret[index++] = 0;
    }

    for (int i = 1; i < sLen - pLen + 1; i++)
    {
        sCount[s[i - 1] - 'a']--;
        sCount[s[i + pLen - 1] - 'a']++;
        if (sCount == pCount)
        {
            ret[index++] = i;
        }
    }
    return ret;
}

int main()
{
    vector<int> r = findAnagrams("cbaebabacd", "abc");

    return 0;
}